# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libarchive

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.1.2
pkgrel=3
pkgdesc="library that can create and read several streaming archive formats (mingw-w64)"
arch=('any')
url="http://libarchive.googlecode.com"
license=("BSD")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-libgnurx" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=(${MINGW_PACKAGE_PREFIX}-gcc-libs
    ${MINGW_PACKAGE_PREFIX}-bzip2
    ${MINGW_PACKAGE_PREFIX}-expat
    ${MINGW_PACKAGE_PREFIX}-lzo2
    ${MINGW_PACKAGE_PREFIX}-nettle
    ${MINGW_PACKAGE_PREFIX}-openssl
    ${MINGW_PACKAGE_PREFIX}-libiconv
    ${MINGW_PACKAGE_PREFIX}-xz
    ${MINGW_PACKAGE_PREFIX}-zlib)
options=('!libtool' 'strip')
source=("http://libarchive.org/downloads/libarchive-$pkgver.tar.gz"
    "0001-mtree-fix-line-filename-length-calculation.patch"
    'libarchive-3.1.3-CVE-2013-0211_read_buffer_overflow.patch')
md5sums=('efad5a503f66329bb9d2f4308b5de98a'
         '9727baf88b928417d5d1269891b1209a'
         '6954a585c309dc548d1f2b05f2f3cfcb')

prepare() {
  cd "$srcdir/libarchive-$pkgver"
  patch -Np1 -i "$srcdir/0001-mtree-fix-line-filename-length-calculation.patch"
  patch -Np1 -i "$srcdir/libarchive-3.1.3-CVE-2013-0211_read_buffer_overflow.patch"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ${srcdir}/${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
  --with-expat \
  --without-xml2
  
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="$pkgdir" install
  #rm -r "${pkgdir}${MINGW_PREFIX}/share"
}
